package com.shaobufan.museum.controllar;

import com.shaobufan.museum.common.BaseResponse;
import com.shaobufan.museum.common.ResultUtils;
import com.shaobufan.museum.pojo.request.exhibit.MuseumExhibitRequest;
import com.shaobufan.museum.pojo.vo.MuseumExhibitVo;
import com.shaobufan.museum.service.MuseumExhibitService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/exhibit")
public class ExhibitController {
    @Resource
    MuseumExhibitService museumExhibitService;

    @ApiOperation("获取所有展览列表")
    @GetMapping("/all")
    public BaseResponse<List<MuseumExhibitVo>> getAllExhibit() {
        List<MuseumExhibitVo> museumExhibitVoList = museumExhibitService.searchExhibitByName(null);
        return ResultUtils.success(museumExhibitVoList, "获取所有展览列表");
    }

    @ApiOperation("添加展览")
    @PostMapping("/add")
    public BaseResponse<Boolean> addExhibit(@RequestBody MuseumExhibitRequest museumExhibitRequest) {
        String exName = museumExhibitRequest.getExName();
        String exDetail = museumExhibitRequest.getExDetail();
        String exImage = museumExhibitRequest.getExImage();
        LocalDate exStart = museumExhibitRequest.getExStart();
        LocalDate exEnd = museumExhibitRequest.getExEnd();

        Boolean added = museumExhibitService.addExhibit(exName, exDetail, exImage, exStart, exEnd);

        return ResultUtils.success(added, "添加成功");
    }

    @ApiOperation("根据id获取展览信息")
    @GetMapping("/id/{params}")
    public BaseResponse<MuseumExhibitVo> getExhibitById(@PathVariable Integer params) {
        MuseumExhibitVo museumExhibitVo = museumExhibitService.searchExhibitById(params);
        return ResultUtils.success(museumExhibitVo, "展览信息");
    }
}